package crm.servlet;

import java.io.IOException;
import java.nio.channels.NonWritableChannelException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

import crm.dto.Page;
import crm.service.ContractService;
import crm.service.impl.ContractServiceImpl;

 
public class ContractListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
    private ContractService contractService = new ContractServiceImpl();
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		doPost(request, response);
		
	}

	
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		String pageSize = request.getParameter("pageSize");
		String pageNO = request.getParameter("pageNO");
		
		try {
			
			
			Page contractList = contractService.getContractList(Integer.parseInt(pageNO), Integer.parseInt(pageSize));
			
			
			String json = JSON.toJSONString(contractList,SerializerFeature.WriteDateUseDateFormat);
			
			response.getWriter().write(json);
			
		} catch (NumberFormatException | InstantiationException | IllegalAccessException | NoSuchFieldException
				| SecurityException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		

		
	}

}
